<%@page import="com.sun.xml.internal.txw2.Document"%>
<%@page import="java.rmi.Naming"%>
<%@page import="server.ForumHandlerInt"%>
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">







<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script type="text/javascript" src="jquery.js"></script>
<%@ include file="scripts.jsp" %>


<script type="text/javascript">
function loadXMLDoc()
{
	
var xmlhttp;
var params;

params = "postTitle="+document.addPost.postTitle.value+"&postContent="+document.addPost.postContent.value;

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  
xmlhttp.open("POST","addPostVa.jsp",false);

//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");


xmlhttp.send(params);



if (xmlhttp.status != 200)
{
	document.write(xmlhttp.responseText);
	return "false"
}
return xmlhttp.responseText;
}
</script>



<%
	String topicName = request.getParameter("topicName");
	int topicId = Integer.parseInt(request.getParameter("topicId"));
%>



<!-- script for validating forms fields are all filled -->
<script type="text/javascript">
function validate_form( )
{
    valid = true;

    if ( document.addPost.postTitle.value == "" )
    {
        alert ( "Please fill in the 'post title' box." );
        valid = false;
        return valid;
    }
    if ( document.addPost.postContent.value == "" )
    {
        alert ( "Please fill in the 'post content' box." );
        valid = false;
        return valid;
    }
    
    var result = loadXMLDoc();
    
    
    if (result == "false")
    	return false;
    
    return valid;
}
</script>



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Add Post</title>
    <link href="styles.css" rel="stylesheet" type="text/css">
    <link href="tableDesign.css" rel="stylesheet" type="text/css">
    <script language="JavaScript" type="text/JavaScript">
		<!--
		function MM_preloadImages() { //v3.0
		  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
			var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
		}
		-->
	</script>
</head>



















<body link="#6C8EBD">
<div id="main"> 
	<div id="header">
		<div id="logo"><img src="Images/logo1.jpg" alt="logo" width="490" height="182"></div>
		<div id="picture"><img src="Images/logo2.jpg" alt="pic" width="289" height="156"></div>
	</div>
	<div id="line"><img src="Images/line.jpg" alt="line" width="779" height="4"></div>
    <div id="navigation">
		ADD POST TO TOPIC:<%=topicName%>
	</div>
	<div id="line2"><img src="Images/line.jpg" alt="line" width="779" height="4"></div>
	<div id="text" ice:editable="*">
		<div id="bar">
			<div class="bluetxt" id="linktxt">
			      <p><a href="friends.jsp">manage friends</a></p>
      <p><a class="bluetxt" href="mainScreen.jsp"> main screen</a>  </p>
      <p><a class="bluetxt" href="topics.jsp?forumId=<%=(Integer)session.getAttribute("forumId")%>&forumName=<%=(String)session.getAttribute("forumName")%>"> forum: <%=(String)session.getAttribute("forumName")%></a>  </li>
  	  <p><a class="bluetxt" href="posts.jsp?topicId=<%=topicId%>&topicName=<%=topicName%>"> topic: <%=topicName%></a>  </p>
        <p><a class="bluetxt" href="index.jsp"  target="_top" onClick= "logoutFunc();">logout</a>  </p>
           </div>
		</div>
		<div id="text2">
			<div class="contentTXT" id="text2txt">
<form name ="addPost" action="posts.jsp?topicId=<%=topicId%>&topicName=<%=topicName%>" method="post" onsubmit="return validate_form ( );">
  <table width="283" border="0">
      <tr>
        <th width="120" scope="row">Post title</th>
        <td width="153"><input name="postTitle" type="text"  maxlength="45" value="" /></td>
      </tr>
      <tr>
        <th width="120" scope="row">Post content</th>
        <td width="153"><textarea rows="3" cols="15" name="postContent" type="text" maxlength="400" value=""></textarea></td>
      </tr>
    </table>
    <input name="addPost" type="submit" value="add post"/>
  

</form>
			</div>
		</div>
	</div>
<div id="Num"><img src="Images/line.jpg" alt="line" width="779" height="4"></div>
<div id="footer">
<div class="footerTXT" id="footertxt"><a class="footerTXT">Designed by ariel nir yuri gilad itzhaki and marina</a> </div>   </div>
</div>
</div>

</body>

</html>